package com.miao.im.dto;

import com.miao.im.common.Constant;
import com.miao.im.common.Message;
import com.miao.im.common.enums.Command;
import com.miao.im.common.enums.MessageType;
import lombok.Data;

import java.io.Serializable;

/**
 * @Auther: miaoguoxin
 * @Date: 2021/4/25 20:25
 * @Description:
 */
@Data
public class SocketMessageDto implements Serializable {
    /**头长度*/
    private Integer headerLength;
    /**版本号*/
    private Integer version;
    /**{@link MessageType}*/
    private Integer messageType;
    /**请求序号*/
    private Long sequence;
    /**指令类型 {@link Command}*/
    private Integer commandType;
    /**消息体长度*/
    private Integer bodyLength;
    /**消息体*/
    private byte[] body;

    public SocketMessageDto() {
    }

    public SocketMessageDto(Integer version, Integer messageType, Long sequence, Integer commandType, byte[] body) {
        this.headerLength = Constant.HEADER_LENGTH;
        this.version = version;
        this.messageType = messageType;
        this.sequence = sequence;
        this.commandType = commandType;
        this.body = body;
        this.bodyLength = body.length;
    }

    public SocketMessageDto(Message message) {
        this.headerLength = message.getHeaderLength();
        this.version = message.getVersion();
        this.messageType = message.getMessageType();
        this.sequence = message.getSequence();
        this.commandType = message.getCommandType();
        this.bodyLength = message.getBodyLength();
        this.body = message.getBody();
    }
}

